﻿
using System;

namespace Northwind.Data
{
    /// <summary>
    /// add user-defined business specific codes in partial class
    /// </summary>
    public partial class Category
    {
        // **************************************** //
        #region [ member variables ]

        private ProductCollection m_prodCollection;

        public void AddProduct(Product prod)
        {
            prod.CategoryID = this.CategoryID;
            m_prodCollection.Add(prod);
        }

        #endregion

        // **************************************** //
        #region [ override virtual methods  ]

        protected override void SetDefaults()
        {
            base.SetDefaults();
            m_prodCollection = new ProductCollection();
        }

        protected override void AfterCommit()
        {
            base.AfterCommit();

            foreach (Product prod in m_prodCollection)
                prod.CategoryID = this.CategoryID;

            m_prodCollection.BatchSave();
        }

        #endregion
    }
}